<template>
  <el-breadcrumb class="app-breadcrumb" separator="/">
    <transition-group name="breadcrumb">

      <el-breadcrumb-item v-for="(menu,index) in curMenu" :key="menu.code">
        <span class="no-redirect">{{ menu.title }}</span>
      </el-breadcrumb-item>
    </transition-group>
  </el-breadcrumb>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      levelList: null
    }
  },
  computed: {
    ...mapGetters(['menus', 'curMenu'])
  },
  watch: {
    $route() {
      this.getBreadcrumb()
    }
  },
  created() {
    this.getBreadcrumb()
  },
  methods: {
    getBreadcrumb() {
      let matched = this.$route.matched.filter(item => item.name)
      const first = matched[0]
      if (first && first.name !== 'dashboard') {
        matched = [{ path: '/', meta: { title: '首页' } }].concat(
          matched
        )
      }
      this.levelList = matched
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .app-breadcrumb.el-breadcrumb {
    display: inline-block;
    margin-left: 10px;
    font-size: 14px;
    line-height: 36px;
    .no-redirect {
      color: #909399;
      cursor: text;
    }
  }
</style>
<style rel="stylesheet/scss" lang="scss" scoped>
  .el-breadcrumb__inner.is-link,
  .el-breadcrumb__inner a {
    color: #909399;
  }

  .el-breadcrumb__inner.is-link,
  .el-breadcrumb__inner a:hover {
    color: #303133;
  }
</style>
